package org.LZQ.ShortLink.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.LZQ.ShortLink.admin.common.convention.result.Result;
import org.LZQ.ShortLink.admin.remote.RemoteService;
import org.LZQ.ShortLink.admin.remote.ShortLinkActualRemoteService;
import org.LZQ.ShortLink.admin.remote.dto.req.ShortLinkGroupStatsAccessRecordReqDTO;
import org.LZQ.ShortLink.admin.remote.dto.req.ShortLinkGroupStatsReqDTO;
import org.LZQ.ShortLink.admin.remote.dto.req.ShortLinkStatsAccessRecordReqDTO;
import org.LZQ.ShortLink.admin.remote.dto.req.ShortLinkStatsReqDTO;
import org.LZQ.ShortLink.admin.remote.dto.resp.ShortLinkStatsAccessRecordRespDTO;
import org.LZQ.ShortLink.admin.remote.dto.resp.ShortLinkStatsRespDTO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
public class LinkStatsController {
    private final ShortLinkActualRemoteService shortLinkActualRemoteService = new ShortLinkActualRemoteService(){};

    private final RemoteService remoteService;
    @GetMapping("/api/shortLink/admin/stats")
    public Result<ShortLinkStatsRespDTO> shortLinkStats(ShortLinkStatsReqDTO requestParam) {
        return remoteService.shortLinkStats(requestParam.getFullShortUrl(),
                requestParam.getGid(),
                requestParam.getEnableStatus(),
                requestParam.getStartDate(),
                requestParam.getEndDate());
    }
    /**
     * 访问分组短链接指定时间内监控数据
     */
    @GetMapping("/api/shortLink/admin/stats/group")
    public Result<ShortLinkStatsRespDTO> groupShortLinkStats(ShortLinkGroupStatsReqDTO requestParam) {
         return remoteService.groupShortLinkStats( requestParam.getGid(),
                 requestParam.getStartDate(),
                 requestParam.getEndDate());
    }
    /**
     * 访问单个短链接指定时间内访问记录监控数据
     * @param requestParam
     * @return
     */
    @GetMapping("/api/shortLink/admin/stats/access-record")
    public Result<Page<ShortLinkStatsAccessRecordRespDTO>> shortLinkStatsAccessRecord(ShortLinkStatsAccessRecordReqDTO requestParam) {
        return remoteService.shortLinkStatsAccessRecord(
                requestParam.getFullShortUrl(),
                requestParam.getGid(),
                requestParam.getStartDate(),
                requestParam.getEndDate(),
                requestParam.getEnableStatus(),
                requestParam.getCurrent(),
                requestParam.getSize()
        );
    }
    /**
     * 访问分组短链接指定时间内访问记录监控数据
     */
    @GetMapping("/api/shortLink/admin/stats/access-record/group")
    public Result<IPage<ShortLinkStatsAccessRecordRespDTO>> groupShortLinkStatsAccessRecord(ShortLinkGroupStatsAccessRecordReqDTO requestParam) {
        return remoteService.groupShortLinkStatsAccessRecord(requestParam.getGid(),
                requestParam.getStartDate(),
                requestParam.getEndDate(),
                requestParam.getCurrent(),
                requestParam.getSize());
    }


}
